<?php
namespace app\course\validate\comment;

use think\Validate;

/**
 * 用户验证
 */
class Comment extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'    =>    ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'star' => [
            'require',
            'regex'=>'^([0-4]\.?[0|5]?)$|^(5\.?0?)$',
        ],
        'content'           => 'require|min:1',
        'reply_user_id'     => 'require|integer',
        'status'            => 'require|in:0,1',
    ];

    protected $field = [
        'star'      => '点评分数',
        'content'   => '点评描述'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'    =>    '错误信息'
     *
     * @var array
     */
    protected $message = [
        'star.require'      => '请确认课程评分',
        'star.regex'        => '课程评分为1到5星',
        'content.require'   => '请输入内容',
        'content.min'       => '点评内容至少一个字符',
        'status.in'         => '参数错误',
        'reply_user_id'     => '回复用户不能为空',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'add'       => ['star', 'content'],
        'addReply'  => ['reply_user_id', 'content'],
        'like'      => ['status'],
    ];

}
